package com.scm.servlet.vender;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.scm.dao.VenderDao;
import com.scm.model.Vender;
import com.scm.util.StringUtil;
@WebServlet("/main/pomain/changevender")
public class ChangeVenderServlet extends HttpServlet{
	private static final long serialVersionUID = 5820811447576444575L;
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		String vendercode = req.getParameter("vendercode").trim();
		String name = req.getParameter("name").trim();
		String password = req.getParameter("password").trim();
		if(StringUtil.isEmpty(password)) {
			password=vendercode;
		}
		String contactor = req.getParameter("contactor").trim();
		String address = req.getParameter("address").trim();
		String postcode = req.getParameter("postcode").trim();
		String tel = req.getParameter("tel").trim();
		String fax = req.getParameter("fax").trim();
		String createdate = req.getParameter("createdate").trim();
		Vender vender = new Vender();
		vender.setVenderCode(vendercode);
		vender.setName(name);
		vender.setPassword(password);
		vender.setPostCode(postcode);
		vender.setAddress(address);
		vender.setContactor(contactor);
		vender.setTel(tel);
		vender.setFax(fax);
		vender.setCreateDate(createdate);
		VenderDao venderdao = new VenderDao();
		try {
			venderdao.change(vender);
			PrintWriter pw = resp.getWriter();
			pw.print("修改成功");
			pw.flush();
			pw.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
